-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: l2 metrics api integration #64
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposing an alternative for the sake of correctness in case you consider it adds some value. Looking good!
@@ -18,13 +18,19 @@ const urlArraySchema = z | |||
message: "Must be a comma-separated list of valid URLs", | |||
}); | |||
|
|||
const urlArrayMapSchema = z.record( | |||
z.union([z.coerce.number().int(), z.string().regex(/^\d+$/)]), // key: number or string number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super edge case but would the key "04"
be validated with this ruleset? Should we invalidate a chain id starting with a 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's fine, chain ids are numbers actually but JSON doesn't allow numbers as key type so if you write, "04" to us it's the same as "4"
apps/api/src/common/config/index.ts
Outdated
const env = validationSchema.safeParse(process.env); | ||
const env = validationSchema.safeParse({ | ||
...process.env, | ||
L2_RPC_URLS_MAP: JSON.parse(process.env.L2_RPC_URLS_MAP || "{}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor drawback this JSON.parse
here could have is that it might throw when parsing an invalid JSON string, causing the nice summary of validation errors to not be generated.
I was curious to see if we could leverage zod
for this; found this conversation that might be useful if you want to move that JSON.parse
to a schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one here, i used the suggestion in the discussion 🙌
@@ -39,6 +39,7 @@ Available options: | |||
| `SHARED_BRIDGE_ADDRESS` | Shared Bridge address | N/A | Yes | | | |||
| `STATE_MANAGER_ADDRESSES` | CSV list of State manager addresses | N/A | Yes | | | |||
| `L1_RPC_URLS` | CSV list of RPC URLs. For example, `https://eth.llamarpc.com,https://rpc.flashbots.net/fast` | N/A | Yes | You can check [Chainlist](https://chainlist.org/) for a list of public RPCs | | |||
| `L2_RPC_URLS_MAP` | JSON from chain id to CSV list of L2 RPC URLs. For example, {"324":"https://mainnet.era.zksync.io,https://zksync.drpc.org"} | N/A | No | You can check [Chainlist](https://chainlist.org/) for a list of public RPCs | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are already parsing a json don't you think having an array of rpcs is better ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced also L1_RPC_URLS to also be a json array since it's easier to read
for (const [chainId, rpcUrls] of Object.entries(l2ChainsConfigMap)) { | ||
const provider = new ZKChainProvider(rpcUrls, logger); | ||
const metricsService = new L2MetricsService(provider, logger); | ||
l2MetricsMap.set(BigInt(chainId), metricsService); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was wondering if it would be better to encapsulate this logic inside the L2MetricsService and you just pass the map as parameter. But this approach seems to be more decoupled. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool af 😎
const urlArraySchema = z | ||
.string() | ||
.transform((str) => str.split(",")) | ||
.refine((urls) => urls.every((url) => z.string().url().safeParse(url).success), { | ||
message: "Must be a comma-separated list of valid URLs", | ||
}); | ||
const urlArraySchema = z.array(z.string().url()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noice
🤖 Linear
Closes ZKS-229 ZKS-202
Description
metrics/zkchain/:chainId
ep